package com.liuheng.spzx.common.exception;

import com.liuheng.spzx.model.vo.common.Result;
import com.liuheng.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice//处理controller层抛出的异常
public class GlobalExceptionHandler {
    //全局异常处理
  @ExceptionHandler(Exception.class)//指定处理的异常
    @ResponseBody//返回JSON格式的数据
    public Result error(){
      return Result.build(null, ResultCodeEnum.SYSTEM_ERROR);
  }
  @ExceptionHandler(CustomException.class)
  @ResponseBody
  public Result error(CustomException exception){
    return Result.build(null,exception.getResultCodeEnum());
  }

}
